

package org.testfire.realm.model.entities;

import javax.persistence.*;
import java.io.Serializable;

/**
 * An Entity bean for the user_groups table, which maps the the userID (not username, exactly) to the
 * groups which said user is a member of.
 */
@Entity
@Table(catalog = "lgsrealm", name = "tbl_user_groups")
public class User_groups implements Serializable {


	/* The user_groups ID, an auto index on the user-groups table. */
    Integer id;
	/* The user id, an auto index on the user table. */
    User user_id;

	/* The group id, an auto index on the group table. */
    Integer group_id;


	/**
	 * Default Constructor.
	 */
    public User_groups() {
    }


	/**
	 * Get the Id for this user_group.
	 * This method also contains the annotations for mapping the Entity field to the DB field;
	 * by setting the GeneratedValue annotation and the Id annotation we inform the
	 * Entity manager of how to map this value to the database table (which was already specified, above).
	 * Note that you will not have a valid ID until this object has been persisted; if you create an instance
	 * the return value will be null.
	 * @return The auto-generated ID value for this entity.
	 */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public Integer getId() {
        return this.id;
    }

	/**
	 * Set the Id for this user_group. A bad idea, since the value is autogenerated.
	 * @param id The id for this table record.
	 */
    public void setId(Integer id) {
        this.id = id;
    }

	/**
	 * Get the User whose userID matches that specifed for this group mapping.
	 * The annotations here mean 'Many user_group mapping records may be created for the same user'.
	 * One userID may exist more than once in the user_groups table that this Entity represents;
	 * which is the point of the map.
	 * user_A is a member of group 'Customers'
	 * user_A is a member of group 'WealthyCustomers'
	 * user_B is a memeber of group 'Admin'
	 * etc.
	 *
	 * We join on the column 'user_id'. We do not need to specify a table, because when
	 * we specifed the datatype for the user_id method variable we used the User Entity datatype.
	 * The persistence layer will recognize that we want a User object, and will Join on the users table
	 * to create it from this user_groups Entity.
	 *
	 * @return The User who ownes this group mapping.
	 */
    @ManyToOne
    @JoinColumn(name = "user_id", nullable = false)
    public User getUser_id() {
        return this.user_id;
    }

	/**
	 * Set the user ID, by passing a User Entity; the persistence context will do the rest if everything
	 * is in sync and managed properly.
	 * @param user_id A User Entity who owns this user-to-group mapping.
	 */
    public void setUser_id(User user_id) {
        this.user_id = user_id;
    }

	/**
	 * Get the group ID for this user-to-group mapping. The ID represents the element in the Groups table
	 * which is the group that the user belongs to.
	 * @return The ID of the group that this user belongs to. (Note that this may not be the only group that the
	 * user belongs to).
	 */
    public Integer getGroup_id() {
        return this.group_id;
    }

	/**
	 * Set the id of the group to which this user belongs; at least, the one user-to-group mapping that this Entity
	 * represents.
	 * @param group_id the id of the group to which this user belongs; at least, the one user-to-group mapping that this Entity
	 * represents.
	 */
    public void setGroup_id(Integer group_id) {
        this.group_id = group_id;
    }

}
